﻿package com.wandian.view.components.ui.mingame.sgj
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.vo.PropVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.ToolTip;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

    public class MaxWinPanel extends Object
    {
        private var _mcWinGamePanel:Sprite;
        private var _tabBar:CLZTabBar;
        private var facade:ApplicationFacade;
        private var _mcWinMaxGame:MovieClip;
        private var _maxWinGame:MaxWinGame;
        private var _mcWinRankGame:MovieClip;
        private var _contenMc:Sprite;

        public function MaxWinPanel(param1:Sprite)
        {
            this.facade = ApplicationFacade.getInstance();
            this._mcWinGamePanel = param1;
            var _loc_2:Array = [[this._mcWinGamePanel["game_btn"]], [this._mcWinGamePanel["rank_btn"]]];
            this._tabBar = new CLZTabBar(_loc_2);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_2[_loc_3][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_3 = _loc_3 + 1;
            }
            this._tabBar.setClickIndex(this._mcWinGamePanel["game_btn"]);
            this._mcWinGamePanel["close_btn"].addEventListener(MouseEvent.CLICK, this.onCloseWinGamePanelHandler);
            return;
        }

        public function startGame(param1:Array) : void
        {
            if (this._maxWinGame != null)
            {
                this._maxWinGame.startGame(param1);
            }
            return;
        }

        public function setRank(param1:Array) : void
        {
            if (this._mcWinRankGame != null)
            {
                this.showRank(param1);
            }
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            this.removeMc();
            switch(event.target.name)
            {
                case "game_btn":
                {
                    this._mcWinMaxGame = GameData.getMovieClip("WinMaxGame");
                    this._maxWinGame = new MaxWinGame(this._mcWinMaxGame);
                    this._mcWinGamePanel.addChild(this._mcWinMaxGame);
                    this._mcWinMaxGame.x = 52.85;
                    this._mcWinMaxGame.y = 163.3;
                    break;
                }
                case "rank_btn":
                {
                    this._mcWinRankGame = GameData.getMovieClip("WinMaxRankPanel");
                    this._mcWinGamePanel.addChild(this._mcWinRankGame);
                    this._mcWinRankGame.x = 31.1;
                    this._mcWinRankGame.y = 154.1;
                    this._contenMc = new Sprite();
                    this._mcWinRankGame.addChild(this._contenMc);
                    this._contenMc.x = 0;
                    this._contenMc.y = 30;
                    this.facade.sendNotification(CLZNoticeName.SGJ_ZP_RANK_REQ, 1);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function showRank(param1:Array) : void
        {
            var _loc_5:MovieClip = null;
            GameData.removeNumChildre(this._contenMc);
            var _loc_2:* = new CLZLlistScrollPanel(1, 415, 32, 0, 0, 272, 418);
            this._contenMc.addChild(_loc_2);
            var _loc_3:* = param1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = GameData.getMovieClip("RankWinMaxInfo");
                _loc_2.setMc(_loc_5, _loc_4, _loc_3);
                if (_loc_4 & 1)
                {
                    _loc_5.bg.gotoAndStop(1);
                }
                else
                {
                    _loc_5.bg.gotoAndStop(2);
                }
                _loc_5.name_txt.text = param1[_loc_4][1];
                _loc_5.gold_txt.text = param1[_loc_4][2];
                _loc_5.time_txt.text = GameData.setDate(param1[_loc_4][3]);
                CLZButton.setButton(_loc_5.btn);
                _loc_5.btn.addEventListener(MouseEvent.CLICK, this.onShare);
                _loc_5.btn.userName = param1[_loc_4][1];
                _loc_5.btn.gold = param1[_loc_4][2];
                _loc_4 = _loc_4 + 1;
            }
            return;
        }

        private function onShare(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as MovieClip;
//            JSFUN.shareMaxWinGameFunc(_loc_2.userName, _loc_2.gold);
            return;
        }

        private function removeMc() : void
        {
            if (this._maxWinGame != null)
            {
                this._maxWinGame = null;
            }
            if (this._mcWinMaxGame != null)
            {
            }
            if (this._mcWinGamePanel.contains(this._mcWinMaxGame))
            {
                this._mcWinGamePanel.removeChild(this._mcWinMaxGame);
                this._mcWinMaxGame = null;
            }
            if (this._mcWinRankGame != null)
            {
            }
            if (this._mcWinGamePanel.contains(this._mcWinRankGame))
            {
                GameData.removeNumChildre(this._contenMc);
                this._contenMc = null;
                this._mcWinGamePanel.removeChild(this._mcWinRankGame);
                this._mcWinRankGame = null;
            }
            return;
        }

        private function onCloseWinGamePanelHandler(event:MouseEvent) : void
        {
            this.facade.sendNotification(CLZNoticeName.HIDE_CLOSE_SGJ_PANEL);
            return;
        }

    }
}
